/**
 * 常用工具方法
 * @type {{isNull, isNotNull, isFunction, log, getQueryString, trim, isWeiXin, getDate}}
 */
var tools = (function () {

    function pri_isNull(obj) {

        if (obj == null || typeof obj == "undefined" || obj == "" || obj.length == 0) {
            return true;
        }

        return false;
    }

    return {
        isNull: function (obj) {
            return pri_isNull(obj);
        },
        isNotNull: function (obj) {
            return !pri_isNull(obj);
        },
        /**
         * 是否还有下页数据
         * @param list
         * @param pageSize
         * @returns {boolean}
         */
        isNextPage: function (list, pageSize) {
            var page = 10;
            if (tools.isNotNull(pageSize)) {
                page = pageSize;
            }
            if (tools.isNotNull(list) && list.length == page) {
                return true;
            }
            return false;
        },
        isFunction: function (obj) {
            return typeof obj == "function";
        },
        log: function (msg) {
            console.dir(msg);
        },
        getQueryString: function (name) {
            var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
            if (result == null || result.length < 1) {

                return "";

            }
            return result[1];
        },
        /**
         * 去除空字符串
         * @param str 来源字符串
         * @param is_global 是否去除中间的空格
         * @returns {string|XML|void|*}
         */
        trim: function (str, is_global) {
            var result;
            result = str.replace(/(^\s+)|(\s+$)/g, "");
            if (is_global) {
                result = result.replace(/\s/g, "");
            }
            return result;
        },
        isWeiXin: function () {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                return true;
            } else {
                return false;
            }
        },
        getDate: function (strDate) {
            strDate = strDate.replace(/-/g, "/");
            return new Date(strDate);
        },
        uniqueId: function () {
            var ramdomLength = 11;
            return Number(Math.random().toString().substr(3, ramdomLength) + Date.now()).toString(36);
        }
    }
})();

var layerTool = (function () {

    return {
        loading: function (msg) {
            var m = "加载中";
            if (tools.isNotNull(msg)) {
                m = msg;
            }
            return layer.open({
                type: 2,
                shadeClose: false,
                content: m
            });
        },
        msg: function (msg) {
            layer.open({
                content: msg
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
        },
        alert: function (content) {
            layer.open({
                content: content
                , btn: '取消'
            });
        }
    }
})();